package cn.fzu.panel;

import cn.fzu.MineLabelListener;
import cn.fzu.frame.StartFrame;
import cn.fzu.label.MineLabel;
import cn.fzu.util.Tools;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;

/**
 * ClassName : cn.fzu.panel.MineField
 * Desc : 雷区
 *
 * @author : LINPQ
 * @date : 2021/3/27 14:40
 */
public class MineField extends JPanel {

   private MineLabel[][] mineLabels;
   private StartFrame startFrame;
    MineLabelListener mineLabelListener;

    public MineField(StartFrame startFrame) {
        this.startFrame = startFrame;
        Border borderIn = BorderFactory.createLoweredBevelBorder();
        Border borderOut = BorderFactory.createEmptyBorder(5, 10, 10, 10);
        Border border = BorderFactory.createCompoundBorder(borderOut, borderIn);
        this.setBorder(border);
        this.setBackground(Color.lightGray);

        this.setLayout(new GridLayout(Tools.rows,Tools.cols));
        mineLabels = new MineLabel[Tools.rows][Tools.cols];
         mineLabelListener = new MineLabelListener(startFrame);

        for (int i = 0; i < Tools.rows ; i++) {
            for (int j = 0; j < Tools.cols ; j++) {
                mineLabels[i][j] = new MineLabel();
                mineLabels[i][j].setIcon(Tools.iiblank);
                mineLabels[i][j].setRow(i);
                mineLabels[i][j].setCol(j);
                mineLabels[i][j].addMouseListener(mineLabelListener);
                add(mineLabels[i][j]);
            }
        }
    }

    public MineLabel[][] getMineLabels() {
        return mineLabels;
    }

    public void setMineLabels(MineLabel[][] mineLabels) {
        this.mineLabels = mineLabels;
    }

    public StartFrame getStartFrame() {
        return startFrame;
    }

    public void setStartFrame(StartFrame startFrame) {
        this.startFrame = startFrame;
    }

    public MineLabelListener getMineLabelListener() {
        return mineLabelListener;
    }

    public void setMineLabelListener(MineLabelListener mineLabelListener) {
        this.mineLabelListener = mineLabelListener;
    }
}
